<?php
include( "admin/now5_header.php" );
$bettype = 36;
$sql = "select * from bet where bettype={$bettype} and lotto_id=" . $lotto_id . " and rame in (0,9)";
$percent = 0;
$betcount = array();
$lostwin = array();
$totalamount = array();
$betids = array(21, 31, 41, 51);
$ary = array();
foreach ($betids as $betid)
{
    $totalamount[$betid] = 0;
    $betcount[$betid] = 0;
    $ary[$betid] = array();
    $i = 0;
    while ($i < 50)
    {
        $ary[$betid][$i] = array("num" => "", "amount" => 0);
        $lostwin[$betid][$i] = 0;
        ++$i;
    }
}
$sql .= " order by amount desc, numbers";
$rs = getdb($sql);

while (!$rs->eof)
{
    $percent = $rs->f['upercent'];
    if (0 < $percent)
    {
        $percent /= 100;
    }
    $p = explode("|", $rs->f['numbers']);
    $type = $p[0];
    $num = $p[1];
    $tmp = $percent * $rs->f['amount'];
    $n = Scan_LM_Array($type, $num, $ary, 50);
    if ($n < 0)
    {
        $j = Empty_LM_Array($type, $ary, 50);
        $ary[$type][$j]['num'] = $num;
        $ary[$type][$j]['amount'] = $tmp;
    }
    else
    {
        $ary[$type][$n]['amount'] ++;
    }
    $totalamount[$type] ++;
    $rs->movenext();
}
$rs->close();
$sql = "select * from bet2 where lotto_id=" . $lotto_id . " and bettype={$bettype} and rame in (0,9)";
$rs = getdb($sql);

while (!$rs->eof)
{
    $backs = $rs->f['back5'];
    $percent = $rs->f['percent255'];
    if (0 < $percent)
    {
        $percent /= 100;
    }
    $p = explode("|", $rs->f['numbers']);
    $type = $p[0];
    $num = $p[1];
    $tmp = $percent * $rs->f['amount'];
    $n = Scan_LM_Array($type, $num, $ary, 50);
    if ($n < 0)
    {
        $j = Empty_LM_Array($type, $ary, 50);
        if (0 <= $j)
        {
            $ary[$type][$j]['num'] = $num;
            $ary[$type][$j]['amount'] = $tmp;
        }
    }
    else
    {
        $ary[$type][$n]['amount'] ++;
    }
    ++$betcount[$type];
    $totalamount[$type] ++;
    $rs->movenext();
}
$rs->close();
$sql = "select * from bet8 where lotto_id=" . $lotto_id . " and bettype={$bettype} and rame in (0,9)";
$rs = getdb($sql);
while (!$rs->eof)
{
    $p = explode("|", $rs->f['numbers']);
    $type = $p[0];
    $num = $p[1];
    $tmp = $rs->f['amount'];
    $n = Scan_LM_Array($type, $num, $ary, 50);
    if ($n < 0)
    {
        $j = Empty_LM_Array($type, $ary, 50);
        if (0 <= $j)
        {
            $ary[$type][$j]['num'] = $num;
            $ary[$type][$j]['amount'] = 0 - $tmp;
        }
    }
    else
    {
        $ary[$type][$n]['amount'] --;
    }
    ++$betcount[$type];
    $totalamount[$type] --;
    $rs->movenext();
}
$rs->close();
$list = array();
foreach ($betids as $betid)
{
    $list[$betid] = "";
    if (0 < $betcount[$betid])
    {
        $i = 0;
        while ($i < 50)
        {
            $lostwin[$betid][$i] = 0 - $ary[$betid][$i]['amount'];
            ++$i;
        }
        asort($lostwin[$betid]);
        reset($lostwin[$betid]);
        $i = 0;
        $list[$betid] = "";
        foreach ($lostwin[$betid] as $key => $val)
        {
            if ($i < 30)
            {
                $c = $ary[$betid][$key]['num'];
                $n = $ary[$betid][$key]['amount'];
                if ($c != "")
                {
                    $numbers = "{$betid}|{$c}";
                    $url = "op.php?op=agent&fp=betlist1&dt1=" . $open . "&dt2=" . $open . "&bettype={$bettype}&page=-1&order=2&numbers=" . $numbers;
                    $list .= $betid;
                    $list .= $betid;
                    $list .= $betid;
                    ++$i;
                }
            }
        }
    }
    $tpl->set("money" . $betid, $totalamount[$betid]);
    $tpl->set("list" . $betid, $list[$betid]);
}
$rs = getdb("select * from rate{$bettype} where lotto_id=" . $lotto_id . " LIMIT 1");
if ($rs->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$tpl->load("main", "now7.htm");
$tpl->set("jslang", $g_conf['language']);
$tpl->show("main");
$ui->footer();
?>